package org.arrowmania.scenes.classes;

import org.arrowmania.engine.beans.Point;
import org.arrowmania.engine.beans.RectArea;

public class GameConvertor {
	public static GameConvertor make(RectArea mDisplay, RectArea mWorld, Point<Float> startPoint){
		return new GameConvertor(mDisplay, mWorld, startPoint);
	}
	
	private GameConvertor(RectArea mDisplay, RectArea mWorld, Point <Float> startPoint) {
		side = mDisplay.width/mWorld.width/1.2f;
		indent = 0.1f * side;
		
		this.startPoint = Point.make(indent + side/2f, (mDisplay.height - mDisplay.width)/2 + indent + side/2f);
	}
	
	public Point<Float> convertWorldPointToDisplayPoint(Point<Integer> p){
		float x = startPoint.x + (side + 2*indent)*p.x;
		float y = startPoint.y + (side + 2*indent)*p.y;
		return Point.make(x, y);
	}
	
	public Point<Integer> convertDisplayPointToWorldPoint(Point<Float> p){
		float x = (p.x - startPoint.x)/(side + 2*indent);
		float y = (p.y - startPoint.y)/(side + 2*indent);
		
		return Point.make((int)x, (int)y);
	}
	
	private final Point <Float> startPoint;
	
	private final float indent;
	private final float side;
}
